<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <title>登录页面</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
            margin: 0;
            background-color: #f0f0f0;
        }
        .login-container {
            background-color: #fff;
            padding: 20px;
            border-radius: 8px;
            box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
            width: 300px;
            text-align: center;
        }
        .form-group {
            margin-bottom: 15px;
        }
        label {
            display: block;
            margin-bottom: 5px;
        }
        input[type="text"], input[type="password"] {
            width: 100%;
            padding: 8px;
            box-sizing: border-box;
        }
        button {
            width: 100%;
            padding: 10px;
            background-color: #007BFF;
            color: #fff;
            border: none;
            border-radius: 4px;
            cursor: pointer;
            margin: 5px 0;
        }
        .button-container {
        margin-top: 15px;
        text-align: center;
    }

    </style>
</head>
<body>
    <div class="login-container">
        <h2>登录</h2>
        <form id="loginForm">
            <div class="form-group">
                <label for="username">用户名:</label>
                <input type="text" id="username" name="username" placeholder="用户名" required>
            </div>
            <div class="form-group">
                <label for="password">密码:</label>
                <input type="password" id="password" name="password" placeholder="密码" required>
            </div>
            <div class="button-container">
                <button type="submit" id="signin">登录</button>
            </div>
            <div class="button-container">
                <button type="submit" id="signup">注册</button>
            </div>
            <div id="resultContainer"></div>
        </form>
    </div>

    <script src="/static/jquery-3.7.1/jquery-3.7.1.min.js"></script>
    <script type="text/javascript" >
           $(document).ready(function() {
            $('#signin').click(function() {
               event.preventDefault(); // 阻止表单的默认提交行为
            //window.location.href = '/home/homeindex.html';
            const username = $('#username').val();
            const password = $('#password').val();
            // 使用Ajax发送POST请求
            $.ajax({
                url: '/mgr/api/signin',
                type: 'POST',
            data :{
                username:username,
                password:password
            },
            success: function(data) {
                 // 当成功保存数据后，将后端返回的消息显示在页面上
                     if (data.code == 0){
                     window.location.href = 'frame';
                     }
                     else {
                    // 如果登录失败，可以在页面上显示错误信息
                    $('#resultContainer').html('<p>登录失败，请重试。</p>');
                    }
                 },
                 error: function(error) {
                    console.log('Error:', error);
                 }
            });
        });
    });
        $(document).ready(function() {
            $('#signup').click(function() {
                event.preventDefault(); // 阻止表单的默认提交行为
                window.location.href = 'signup';
            });
        });
  </script>
</body>
</html>
